package com.itheima.reggie.web.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//点餐端套餐的表现层控制器
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    //点餐端根据分类id和状态码查询套餐列表
    @GetMapping("/list")
    public ResultInfo findByCategoryAndStatus(Long categoryId) {
        //调用service
        List<Setmeal> setmealList = setmealService.findByCategoryAndStatus(categoryId);
        //返回
        return ResultInfo.success(setmealList);
    }

    //点餐端点击套餐图片显示套餐信息
    @GetMapping("/dish/{id}")
    public ResultInfo findById(@PathVariable Long id) {
        //调用service
        List<Dish> dishList = setmealService.findBySetmealAndDish(id);
        //返回
        return ResultInfo.success(dishList);
    }
}
